import { createRouter, createWebHistory } from 'vue-router'
import HelloWorld from '../views/HelloWorld.vue'
import roles from '../views/admin/roles.vue'
import resource from '../views/admin/resource.vue'
import rolestwo from '../views/admin/rolestwo.vue'
import rolesfenpei from '../views/admin/rolesfenpei.vue'
import login from '../views/admin/login.vue'
import admin from '../views/admin/admin.vue'

const routes = [{
        path: '/',
        name: 'HelloWorld',
        component: HelloWorld
    },
    {
        path: '/admin',
        name: 'admin',
        component: admin,
        children:[{
            path: '/rolestwo',
            name: 'rolestwo',
            component: rolestwo
        },{
            path: '/rolesfenpei',
            name: 'rolesfenpei',
            component: rolesfenpei
        },{
            path: '/logins',
            name: 'logins',
            component: login
        }]
    },
    {
        path: '/logins',
        name: 'logins',
        component: login
    },
    {
        path: '/roles',
        name: 'roles',
        component: roles
    },
    {
        path: '/resource',
        name: 'resource',
        component: resource
    },
    // {
    //     path: '/rolestwo',
    //     name: 'rolestwo',
    //     component: rolestwo
    // },
    // {
    //     path: '/rolesfenpei',
    //     name: 'rolesfenpei',
    //     component: rolesfenpei
    // },

    // 其他路由...  
]

const router = createRouter({
    history: createWebHistory(""),
    routes
})

// router.beforeEach((to, from, next) => {
//     alert(to.path)
//     var reslist = ['/logins', '/rolesfenpei', '/roles']
//     if (reslist.indexOf(to.path) == -1) {
//         var token = localStorage.getItem('token')
//         if (token) {
//             //验证是否在权限列表中
//             var menulist = localStorage.getItem('permmison')
//             var mlist = JSON.parse(menulist)
//             if (mlist.indexOf(to.path) >= 0) {
//                 next()
//             } else {
//                 alert("无权访问此页面")
//                 next({ "name": 'Login' })
//             }
//         } else {
//             next({ "name": 'Login' })
//         }
//     }
//     next()
// })

export default router